package cn.gmph.blog.service.term.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;

import cn.gmph.blog.service.term.dao.helper.TermRelationshipsProvider;
import cn.gmph.blog.service.term.entity.TermRelationshipsDO;;

public interface TermRelationshipsDAO {
    @Results({ @Result(column = "object_id", property = "objectId"), @Result(column = "term_taxonomy_id", property = "termTaxonomyId"), @Result(column = "term_order", property = "termOrder") })
    @Select("SELECT * FROM wp_term_relationships ")
    public List<TermRelationshipsDO> findAll();

    @Results({ @Result(column = "object_id", property = "objectId"), @Result(column = "term_taxonomy_id", property = "termTaxonomyId"), @Result(column = "term_order", property = "termOrder") })
    @Select("SELECT * FROM wp_term_relationships WHERE object_id = #{id}")
    public TermRelationshipsDO getById(@Param("id") Long id);

    @Insert("INSERT into wp_term_relationships(object_id,term_taxonomy_id,term_order) VALUES (#{objectId},#{termTaxonomyId},#{termOrder})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    public void insert(TermRelationshipsDO termRelationships);

    @Delete("DELETE FROM wp_term_relationships WHERE id = #{id}")
    public int deleteById(@Param("id") int id);

    @UpdateProvider(type = TermRelationshipsProvider.class, method = "update")
    public int update(@Param("termRelationships") TermRelationshipsDO termRelationships);

    @Results({ @Result(column = "object_id", property = "objectId"), @Result(column = "term_taxonomy_id", property = "termTaxonomyId"), @Result(column = "term_order", property = "termOrder") })
    @SelectProvider(type = TermRelationshipsProvider.class, method = "pageList")
    public List<TermRelationshipsDO> pageList(@Param("termRelationships") TermRelationshipsDO termRelationships, @Param("pageNum") Integer pageNum, @Param("pageSize") Integer pageSize);

    @SelectProvider(type = TermRelationshipsProvider.class, method = "pageListCount")
    public Integer pageListCount(@Param("termRelationships") TermRelationshipsDO termRelationships);

}